/*
 * ttrss-reader-fork for Android
 * 
 * Copyright (C) 2010 N. Braden.
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 3 as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 */

/**
 * 
 */
package org.ttrssreader.widget;

import org.ttrssreader.R;
import org.ttrssreader.controllers.DBHelper;
import org.ttrssreader.model.CategoryAdapter;
import org.ttrssreader.model.FeedAdapter;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.app.ListFragment;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.app.LoaderManager;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.SearchView.OnQueryTextListener;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

/**
 * @author Jean Calixte
 *
 */
public class WidgetFeedListFragment extends ListFragment{
    FeedAdapter mAdapter;
    String[] dataColumns = { "name" };
    ListFragmentItemClickListener mLFICL;
    
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        
        try{
            /** This statement ensures that the hosting activity implements ListFragmentItemClickListener */
            mLFICL = (ListFragmentItemClickListener) activity;          
        }catch(Exception e){
            Toast.makeText(activity.getBaseContext(), "Exception",Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        
        setEmptyText(getText(R.string.list_empty));
        
        int[] viewIds = { R.id.feed_title };        
        mAdapter = new FeedAdapter(getActivity().getApplicationContext(), -1);
        setListAdapter(mAdapter);
    }

    
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        //super.onListItemClick(l, v, position, id);
        Log.i("WidgetFeedListFragment", "Item clicked: " + mAdapter.getId(position));
        mLFICL.onListFragmentItemClick(WidgetConfigureActivity.Item_Type.TYPE_FEED, mAdapter.getId(position));
    }
    
}
